using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FetCo.Data;
using ADESSA.Business;
using ADESSA.Entities;
using FetCo.Framework;
using FetCo.Web;


public partial class CatProduct : System.Web.UI.UserControl
{
    protected string M_HomeLeft = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadCat();
        M_HomeLeft = AllAds.LoadHomeLeft();
    }
    int count = 0;
    private void LoadCat()
    {
        Criteria cri = new Criteria();
        cri.add("[" + ProductCat._Table + "].[" + ProductCatColumns.CatLevel + "]", 0, Condition.EQUAL, Condition.AND);
        cri.add("[" + ProductCat._Table + "].[" + ProductCatColumns.Enable + "]", 1, Condition.EQUAL, Condition.AND);
        ProductCatCollection _ProductCatCollection = ProductCatService.GetProductCatListByParam("[" + ProductCat._Table + "].[" + ProductCatColumns.SortOrder + "]", OrderDirection.ASC, cri.Criter);
        if (_ProductCatCollection.Count > 0)
        {
            count = _ProductCatCollection.Count;
            rptCat.DataSource = _ProductCatCollection;
            rptCat.DataBind();
           
        }
    }
    protected void rptCat_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        ProductCat _ProductCat = (ProductCat)e.Item.DataItem;
        HtmlAnchor hrfcat = (HtmlAnchor)e.Item.FindControl("hrfcat");
        Literal ltrCat = (Literal)e.Item.FindControl("ltrCat");
        Repeater rptSubCat = (Repeater)e.Item.FindControl("rptSubCat");
        hrfcat.HRef = "ProductList.aspx?idcat=" + _ProductCat.ProCateID + "";
        Criteria cri = new Criteria();
        cri.add("[" + ProductCat._Table + "].[" + ProductCatColumns.CatLevel + "]", 1, Condition.EQUAL, Condition.AND);
        cri.add("[" + ProductCat._Table + "].[" + ProductCatColumns.Parrentid + "]", _ProductCat.ProCateID, Condition.EQUAL, Condition.AND);
        ProductCatCollection _ProductCatCollection = ProductCatService.GetProductCatListByParam("[" + ProductCat._Table + "].[" + ProductCatColumns.SortOrder + "]", OrderDirection.ASC, cri.Criter);
        if (_ProductCatCollection.Count > 0)
        {
            rptSubCat.DataSource = _ProductCatCollection;
            rptSubCat.DataBind();
        }
        ltrCat.Text = _ProductCat.Name;
        int countvalue = e.Item.ItemIndex + 1;
        if (count == countvalue)
        {
            hrfcat.Attributes["class"] = "noborder";
        }
        else
        {
            hrfcat.Attributes["class"] = "";
        }
    }
    protected void rptSubCat_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        ProductCat _ProductCat = (ProductCat)e.Item.DataItem;
        HtmlAnchor hrfsubcat = (HtmlAnchor)e.Item.FindControl("hrfsubcat");
        Literal ltrSubCat = (Literal)e.Item.FindControl("ltrSubCat");
        hrfsubcat.HRef = "ProductList.aspx?idSubcat=" + _ProductCat.ProCateID + "";
        ltrSubCat.Text = _ProductCat.Name;
    }
}
